package com.service;

import com.dao.WebDao;
import com.dto.Person;
import com.dto.Student;
import com.dto.User;
import com.web.WebController;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.Calendar;
import java.util.List;
import java.util.Map;

/**
 * Created by 黑旋风诸葛亮 on 2018/1/30.
 */
@Service
public class WebServiceImpl implements WebService {

    @Autowired
    private WebDao webDao;
    @Autowired
    private HttpSession session;
    @Autowired
    private HttpServletRequest request;

//    @Autowired
//    private WebController controller;


    @Override
    public User checkLand(User user) {



        List<Map<String, Object>> maps = webDao.checkLand(user);

      User us = new User();
//        us.setUserName("456789");

        if(maps !=null){
           us.setUsername("4567");

        }

      return  us;
    }

    public  void message(){

      //webDao.getMessage();
//        System.out.println("fffffffffff");
//        System.out.println("webService");
//        List<Map<String,Object>> list = webDao.selectName();
//        System.out.println(list);
//
//        Person p = new Person();
//        p.name = "";

    }

    @Override
    public String uploadAttach(CommonsMultipartFile file, String originalName) {

        FileItem  fielItem = file.getFileItem();
        Calendar calendar = Calendar.getInstance();
      //  String Path = "/"+String.valueOf(calendar.get(Calendar.YEAR))+"/"+String.valueOf(calendar.get(Calendar.MONTH)+1)+"/";
     //   String originalPath = Path + GlobalConstants.ORIGINAL_SUFFIX + "-"+ originalName;
       String path = "/mnt/argi/release/files";
      String originalPath = "/upload/"+originalName;
        File fileSave=new File(path+File.separatorChar+originalPath);
        try {
            FileUtils.copyInputStreamToFile(fielItem.getInputStream(), fileSave);
        }
        catch (Exception e){


        }
        return  "ff";
    }


    public void sessionTest(){

        session.setAttribute("name","张三");
    }






}
